package com.david.apollo;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;

import java.time.LocalDateTime;

/**
 * @author David
 * @version V1.0
 * @Package com.david.apollo
 * @date 2021/5/5 23:40
 */
public class GetConfigTest {
    public static void main(String[] args) {

        //testGetConfig();
        testDynamicConfig();
    }

    private static void testGetConfig() {
        //VM Options:
        //-Dapp.id=20210505001 ‐Denv=DEV ‐Ddev_meta=http://192.168.219.104:8080
        Config appConfig = ConfigService.getAppConfig();
        //第一个参数key 第二个参数是默认值
        String property = appConfig.getProperty("david.apollo.test", null);
        System.out.println("property = " + property);
    }

    private static void testDynamicConfig() {
        Config appConfig = ConfigService.getAppConfig();
        while(true){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //第一个参数key 第二个参数是默认值
            String property = appConfig.getProperty("david.apollo.test", null);
            System.out.printf("now: %s, david.apollo.test: %s%n", LocalDateTime.now().toString(), property);
        }
    }
}
